﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Data;
using Actuals.Data;
using System.Data;

namespace Actuals.Data
{
   public class DalCodeReview : Dal<ICodeReview, CodeReview>,IDalCodeReview
    {
       private readonly IDalManager _manager;
       private static readonly IDalCodeReview _instance = new DalCodeReview();
       private const string SP_ADDCODEREVIEW = "usp_AddCodeReview";


       public static IDalCodeReview Instance
       {
           get { return _instance ;}
       }
       public DalCodeReview()
       {
           _manager = new DalManager();
       }
       public DalCodeReview(IDalManager manager)
       {
           _manager = manager;
       }
       protected override void Convert(ICodeReview obj, DataRow row)
       {
           obj.CodeReviewId = _manager.GetValue<int>(row,"CodeReviewId");
           obj.CodeSnippet = _manager.GetValue<string>(row,"CodeSnippet");
           obj.SuggestedResolution = _manager.GetValue<string>(row,"SuggestedResolution");
           obj.Description = _manager.GetValue<string>(row,"Description");
           obj.Priority = _manager.GetValue<int>(row,"Priority");
           obj.AssignTo = _manager.GetValue<string>(row,"AssignTo");
       }
       public bool  AddCodeReview(ICodeReview codeReview)
       {
           _manager.StoredProcedureName = SP_ADDCODEREVIEW;
           _manager.AddInParameter("@CodeReviewId",DbType.Int32,codeReview.CodeReviewId);
           _manager.AddInParameter("@CodeSnippet",DbType.String,codeReview.CodeSnippet);
           _manager.AddInParameter("@SuggestedResolution",DbType.String,codeReview.SuggestedResolution);
           _manager.AddInParameter("@Description",DbType.String,codeReview.Description);
           _manager.AddInParameter("@Priority",DbType.Int32,codeReview.Priority);
           _manager.AddInParameter("@AssignTo",DbType.String,codeReview.AssignTo);
           _manager.ExecuteNonQuery();
           return true;


       }


    }
}
       